home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ For TASM / USRGUIDE.PAK / EXCHMOD.ASM < prev    next >
Assembly Source File  |  1996-02-21  |  1KB  |  34 lines

  1. ; Turbo Assembler example. Copyright (c) 1993 By Borland International, Inc.
  2. ;
  3. ; EXCHMOD.ASM
  4. ;
  5. ; Usage: Run tasm on this file and link with exchmod.pas
  6.  
  7.           .MODEL  large,PASCAL
  8.           .CODE
  9. Exchange  PROC FAR var1:DWORD,var2:DWORD,count:WORD
  10.           PUBLIC Exchange;
  11.           cld                   ;exchange goes upward
  12.           mov     dx,ds         ;save DS
  13.           lds     si,var1       ;get first address
  14.           les     di,var2       ;get second address
  15.           mov     cx,count      ;get number of bytes to move
  16.           shr     cx,1          ;get word count (low bit -> carry)
  17.           jnc     ExchangeWords ;if no odd byte, enter loop
  18.           mov     al,es:[di]    ;read odd byte from var2
  19.           movsb                 ;move a byte from var1 to var2
  20.           mov     [si-1],al     ;write var2 byte to var1
  21.           jz      Finis         ;done if only 1 byte to exchange
  22. ExchangeWords:
  23.           mov     bx,-2         ;BX is a handy place to keep -2
  24. ExchangeLoop:
  25.           mov     ax,es:[di]    ;read a word from var2
  26.           movsw                 ;do a move from var1 to var2
  27.           mov     [bx][si],ax   ;write var2 word to var1
  28.           loop    ExchangeLoop  ;repeat "count div 2" times
  29. Finis:
  30.           mov     ds,dx         ;get back Turbo's DS
  31.           ret
  32. Exchange  ENDP
  33.           END
  34.